/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.gtm.base.str;

import bgu.ppm.gtm.base.MutableStrategy;
import bgu.sonar.util.collections.Pair;
import java.util.Iterator;

/**
 *
 * @author User
 */
public class IntegerStrategy implements MutableStrategy {

    private int minValue;
    private MutableStrategy wrapee;

    /**
     * Creates wrapper for BitmapStrategy and initializes it to zero
     * @param minValue
     * @param numberOfVariables
     * @param domainSize
     * @param owningPlayer 
     */
    public IntegerStrategy(int minValue, int numberOfVariables, int domainSize, int owningPlayer) {
        this.minValue = minValue;
        this.wrapee = new BitmapStrategy(numberOfVariables, domainSize, owningPlayer);

        for (int i = 0; i < numberOfVariables; i++) {
            set(i, 0);
        }
    }

    public IntegerStrategy(MutableStrategy wrapee) {
        this.wrapee = wrapee;
        this.minValue = 0;
    }

    public IntegerStrategy(int minValue, MutableStrategy wrapee) {
        this.minValue = minValue;
        this.wrapee = wrapee;
    }
    
    @Override
    public int getOwningPlayer() {
        return wrapee.getOwningPlayer();
    }

    @Override
    public int getNumberOfVariables() {
        return wrapee.getNumberOfVariables();
    }

    @Override
    public int get(int variable) {
        return minValue + wrapee.get(variable);
    }

    @Override
    public Iterator<Pair<Integer, Integer>> iterator() {
        return wrapee.iterator();
    }

    @Override
    public void set(int var, int val) {
        wrapee.set(var, val - minValue);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Strategy{");
        for (int i = 0; i < getNumberOfVariables(); i++) {
            sb.append(get(i)).append(", ");
        }

        if (sb.length() > "Strategy{".length()) {
            sb.delete(sb.length() - ", ".length(), sb.length());
        }

        sb.append("}");

        return sb.toString();
    }
    
}
